<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="static/vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="static/vendor/font-awesome/css/font-awesome.min.css">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" href="static/css/fontastic.css">
    <!-- Google fonts - Poppins -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,700">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="static/css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="static/css/custom.css">
    <link rel="stylesheet" href="static/css/fileinput.css">
    <link rel="stylesheet" href="static/css/viewer.min.css">


    <!-- Favicon-->
    <link rel="shortcut icon" href="static/img/favicon.ico">
    <!-- Tweaks for older IEs-->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
</head>

<body>

    <div id="app">
        <div class="page">
            <!-- Main Navbar-->
            <header class="header">
                <nav class="navbar">
                    <!-- Search Box-->
                    <div class="search-box">
                        <button class="dismiss"><i class="icon-close"></i></button>
                        <form id="searchForm" action="#" role="search">
                            <input type="search" placeholder="What are you looking for..." class="form-control">
                        </form>
                    </div>
                    <div class="container-fluid">
                        <div class="navbar-holder d-flex align-items-center justify-content-between">
                            <!-- Navbar Header-->
                            <div class="navbar-header">
                                <!-- Navbar Brand -->
                                <a href="index.html" class="navbar-brand d-none d-sm-inline-block">
                                    <div class="brand-text d-none d-lg-inline-block"><span>淘书斋后台管理</span></div>
                            </div>
                            <!-- Navbar Menu -->
                            <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center">
                                <!-- Search-->
                                <li class="nav-item d-flex align-items-center">
                                    <a href="#"></a>
                                </li>

                                <!-- Logout    -->
                                <li class="nav-item">
                                    <li @click="logout()">
                                        <a href="#" class="nav-link logout"> <span class="d-none d-sm-inline">退出</span><i class="fa fa-sign-out"></i></a>
                                    </li>
                                </li>
                            </ul>
                        </div>
                    </div>
                </nav>
            </header>
            <div class="page-content d-flex align-items-stretch">
                <!-- Side Navbar -->
                <nav class="side-navbar">
                    <!-- Sidebar Header-->
                    <div class="sidebar-header d-flex align-items-center">
                        <div class="avatar"><img src="static/img/gao.jpg" alt="..." class="img-fluid rounded-circle"></div>
                        <div class="title">
                            <h1 class="h4">{{adminName}}</h1>
                            <p>管理员</p>
                        </div>
                    </div>
                    <!-- Sidebar Navidation Menus--><span class="heading">管理</span>
                    <ul class="list-unstyled">
                        <li>
                            <a href="index.html"> <i class="icon-home"></i>首页</a>
                        </li>
                        <li class="active">
                            <a href="#bookDownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>书本管理</a>
                            <ul id="bookDownDropdown" class="collapse list-unstyled ">
                                <li><a href="book.html">书本列表</a></li>
                                <li><a href="booktype.html">书本类型列表</a></li>
                            </ul>
                        </li>

                        <li>
                            <a href="#orderDownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>订单管理</a>
                            <ul id="orderDownDropdown" class="collapse list-unstyled ">
                                <li><a href="order.html">订单列表</a></li>
                            </ul>
                        </li>

                        <li>
                            <a href="#userDownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>用户管理</a>
                            <ul id="userDownDropdown" class="collapse list-unstyled ">
                                <li><a href="user.html">用户列表</a></li>

                            </ul>
                        </li>


                    </ul><span class="heading">设置</span>
                    <ul class="list-unstyled">
                        <li>
                            <a href="role.html"> <i class="icon-flask"></i>权限管理 </a>
                        </li>
                    </ul>
                </nav>
                <div class="content-inner">
                    <!-- Page Header-->
                    <header class="page-header">
                        <div class="container-fluid">
                            <h2 class="no-margin-bottom">淘书斋</h2>
                        </div>
                    </header>
                    <!-- Breadcrumb-->
                    <div class="breadcrumb-holder container-fluid">
                        <ul class="breadcrumb">
                            <li class="breadcrumb-item"><a href="book.html">书本列表</a></li>
                            <li class="breadcrumb-item active">书本详情 </li>
                        </ul>
                    </div>
                    <!-- Forms Section-->

                    <section class="forms">
                        <div class="container-fluid">
                            <div class="row">

                                <!-- Form Elements -->
                                <div class="col-lg-12">
                                    <div class="card">
                                        <div class="card-close">
                                            <div class="dropdown">
                                                <button type="button" id="closeCard5" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="dropdown-toggle"><i class="fa fa-ellipsis-v"></i></button>

                                            </div>
                                        </div>
                                        <div class="card-header d-flex align-items-center">
                                            <h3 class="h4">书本信息</h3>
                                        </div>
                                        <div class="card-body">
                                            <form class="form-horizontal">
                                                <div class="form-group row">
                                                    <label class="col-sm-1 form-control-label">名称</label>
                                                    <div class="col-sm-3">
                                                        <label class="form-control-label">{{book.bookName}}</label>
                                                    </div>
                                                </div>
                                                <div class="line "></div>
                                                <div class="form-group row">
                                                    <label class="col-sm-1 form-control-label">数量</label>
                                                    <div class="col-sm-6">
                                                        <label class="form-control-label">{{book.bookCount}}</label>
                                                    </div>
                                                </div>
                                                <div class="line "></div>
                                                <div class="form-group row">
                                                    <label class="col-sm-1 form-control-label">价格</label>
                                                    <div class="col-sm-6">
                                                        <label class="form-control-label">{{book.bookPrice}}</label>
                                                    </div>
                                                </div>
                                                <div class="line "></div>
                                                <div class="form-group row">
                                                    <label class="col-sm-1 form-control-label">作者</label>
                                                    <div class="col-sm-6">
                                                        <label class="form-control-label">{{book.bookAuthor}}</label>
                                                    </div>
                                                </div>

                                                <div class="line "></div>
                                                <div class="form-group row ">
                                                    <label class="col-sm-1 form-control-label ">商品类型</label>
                                                    <div class="col-sm-6">
                                                        <label class="form-control-label">{{book.bookType.typeName}}</label>
                                                    </div>

                                                </div>
                                                <div class="line "></div>

                                                <div class="form-group row ">
                                                    <label class="col-sm-1 form-control-label">描述</label>
                                                    <div class="col-sm-9 ">
                                                        <label class="form-control-label">{{book.bookDetail}}</label>
                                                    </div>
                                                </div>
                                                <div class="line "></div>
                                                <div class="form-group row ">
                                                    <label class="col-sm-1 form-control-label ">封面</label>
                                                    <div id="cover" @click="coverPriview()">
                                                        <image :src="book.bookCover" width='170px' height='200px'>

                                                    </div>
                                                </div>
                                                <div class="line "></div>

                                                <div class="form-group row ">
                                                    <label class="col-sm-1 form-control-label ">详细图片</label>
                                                    <div id="file" @click="imgPriview()">
                                                        <template v-for="(item,index) in bookImgArr">
                                                        <image :src="item" width='170px' height='200px'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                        </template>
                                                    </div>
                                                </div>
                                                <div class="line "></div>
                                                <!-- <div class="form-group row has-success ">
                                                <label class="col-sm-3 form-control-label ">Input with success</label>
                                                <div class="col-sm-9 ">
                                                    <input type="text " class="form-control is-valid ">
                                                </div>
                                            </div>
                                            <div class="line "></div>
                                            <div class="form-group row has-danger ">
                                                <label class="col-sm-3 form-control-label ">Input with error</label>
                                                <div class="col-sm-9 ">
                                                    <input type="text " class="form-control is-invalid ">
                                                    <div class="invalid-feedback ">Please provide your name.</div>
                                                </div>
                                            </div>
                                            <div class="line "></div> -->

                                                <!-- <div class="form-group row ">
                                                <label class="col-sm-3 form-control-label ">Button addons</label>
                                                <div class="col-sm-9 ">
                                                    <div class="form-group ">
                                                        <div class="input-group ">
                                                            <div class="input-group-prepend ">
                                                                <button type="button " class="btn btn-primary ">Go!</button>
                                                            </div>
                                                            <input type="text " class="form-control ">
                                                        </div>
                                                    </div>
                                                    <div class="form-group ">
                                                        <div class="input-group ">
                                                            <input type="text " class="form-control ">
                                                            <div class="input-group-append ">
                                                                <button type="button " class="btn btn-primary ">Go!</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div> -->

                                                <div class="form-group row ">
                                                    <div class="col-sm-4 offset-sm-8 ">
                                                        <button type="button" @click="back()" class="btn btn-secondary "></a>返回</button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                        <button v-if="ifPublic" type="button" data-toggle="modal" data-target="#myModal" class="btn btn-danger "></a>下架</button>
                                                        <button v-else type="button" data-toggle="modal" data-target="#publicModal" class="btn btn-success "></a>上架</button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                        <button type="button" @click="evaluate()" class="btn btn-primary "></a>查看评价</button>
                                                    </div>
                                            </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                    </section>

                    <!-- Modal-->
                    <div id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
                        <div role="document" class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h4 id="exampleModalLabel" class="modal-title">确认下架?</h4>
                                    <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                                </div>

                                <div class="modal-footer">
                                    <button type="button" data-dismiss="modal" class="btn btn-secondary">取消</button>
                                    <button type="button" class="btn btn-primary" @click="notpublic()">确认</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Modal-->
                    <div id="publicModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
                        <div role="document" class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h4 id="exampleModalLabel" class="modal-title">确认上架?</h4>
                                    <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                                </div>

                                <div class="modal-footer">
                                    <button type="button" data-dismiss="modal" class="btn btn-secondary">取消</button>
                                    <button type="button" class="btn btn-primary" @click="public()">确认</button>
                                </div>
                            </div>
                        </div>
                    </div>



                    <!-- Page Footer-->
                    <footer class="main-footer ">
                        <div class="container-fluid ">
                            <div class="row ">
                                <div class="col-sm-6 ">
                                    <p class="weui-footer__text">Copyright © 2019 <a style="color:#3f8b81" href="#">抓娃小组</a>&nbsp版权所有</p>
                                </div>
                                <div class="col-sm-6 text-right ">
                                    <p></p>
                                    <!-- Please do not remove the backlink to us unless you support further theme's development at https://bootstrapious.com/donate. It is part of the license conditions. Thank you for understanding :)-->
                                </div>
                            </div>
                        </div>
                    </footer>
                    </div>
                </div>
            </div>

        </div>





        <!-- JavaScript files-->
        <script src="static/vendor/jquery/jquery.min.js "></script>
        <script src="static/vendor/popper.js/umd/popper.min.js ">
        </script>
        <script src="static/vendor/bootstrap/js/bootstrap.min.js "></script>
        <script src="static/vendor/jquery.cookie/jquery.cookie.js ">
        </script>
        <script src="static/vendor/chart.js/Chart.min.js "></script>
        <script src="static/vendor/jquery-validation/jquery.validate.min.js "></script>
        <!-- Main File-->
        <script src="static/js/front.js "></script>
        <script src="static/js/fileinput.js "></script>
        <script src="https://cdn.bootcss.com/bootstrap-fileinput/4.3.5/js/locales/zh.min.js "></script>
        <script src="static/js/viewer-jquery.min.js "></script>
        <script src="static/js/viewer.min.js"></script>
        <script src="static/node_modules/vue/dist/vue.js"></script>



        <script>
            var vm = new Vue({
                el: '#app',
                data: {
                    adminName: '',
                    bookId: '',
                    //服务器:http://47.100.136.219
                    serverIp: 'http://47.100.136.219',
                    ifLocal: false,
                    msg: 'hello',
                    bookImgArr: [],
                    book: {
                        bookCover: ''
                    },
                    publicState: true,
                    ifPublic: true


                },
                mounted() {
                    let _this = this;

                    if (this.ifLocal) {
                        this.serverIp = "http://localhost";
                    }


                    $.ajax({
                        type: "GET",
                        url: _this.serverIp + ":8088/boot/admincommon/info",
                        success: function(response) {
                            if (response.code == 200) {
                                console.log(response.data);
                                _this.adminName = response.data.data.principal.username
                            }
                        },

                    });

                    _this.bookId = getQueryString('id');
                    console.log(_this.bookId);

                    _this.createBook();


                },
                methods: {
                    logout() {
                        let _this = this;
                        $.ajax({
                            url: _this.serverIP + ':8088/boot/logout',
                            type: 'POST',
                            success: function(res, status) {
                                console.log(res);
                                location.href = "login.html";

                            },
                            error: function(res, status) {
                                console.log(res);
                            }
                        });
                    },
                    createBook() {
                        let _this = this;
                        $.ajax({
                            type: "GET",
                            url: _this.serverIp + ":8088/boot/adminbook/book/" + _this.bookId,
                            success: function(response) {
                                if (response.code == 200) {
                                    console.log(response.data.book);
                                    _this.bookImgArr = [];
                                    _this.book.bookCover = '';
                                    _this.book = response.data.book;
                                    _this.ifPublic = response.data.book.ifPublic;
                                    var imgArr = [];

                                    imgArr = response.data.book.detailImg.split(';');
                                    for (i = 0; i < imgArr.length; i++) {

                                        if (imgArr[i].indexOf("http") < 0) {
                                            imgArr[i] = "http:" + imgArr[i];
                                        }
                                        _this.bookImgArr.push(imgArr[i]);

                                    }
                                    console.log(_this.bookImgArr);
                                    if (response.data.book.bookCover.indexOf("http") < 0) {
                                        _this.book.bookCover = "http:" + _this.book.bookCover;
                                    }
                                } else if (response.code == 403) {
                                    alert(response.msg);

                                }
                            }
                        });
                    },

                    coverPriview() {
                        $('#cover').viewer();
                    },
                    imgPriview() {
                        $('#file').viewer();
                    },
                    back() {
                        location.href =
                            "book.html";
                    },
                    evaluate() {
                        location.href = "evaluate.html?id=" + this.bookId;
                    },


                    public() {

                        this.publicState = true;
                        this.updateBookPublic();
                        $("#publicModal").modal("hide");
                    },
                    notpublic() {
                        this.publicState = false;
                        this.updateBookPublic();

                        $("#myModal").modal("hide");
                    },
                    updateBookPublic() {
                        let _this = this;
                        $.ajax({
                            type: "PUT",
                            url: _this.serverIp + ":8088/boot/adminbook/bookpublic",
                            data: {
                                id: _this.book.bookId,
                                publicState: _this.publicState
                            },
                            success: function(response) {
                                if (response.code == 200) {
                                    _this.createBook();

                                } else if (response.code == 403) {
                                    alert(response.msg);

                                }
                            }
                        });
                    },

                },
            });

            function getQueryString(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }
        </script>

</body>

</html>